// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   purchase_apply_ok.java

package qcs.qcs;

import com.jspsmart.upload.SmartUpload;
import include.nseer_cookie.counter;
import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.sql.ResultSet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;

public class purchase_apply_ok extends HttpServlet
{

	public purchase_apply_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		ServletContext dbApplication = dbSession.getServletContext();
		try
		{
			HttpSession session = request.getSession();
			ServletContext context = session.getServletContext();
			String path = context.getRealPath("/");
			counter count = new counter(dbApplication);
			SmartUpload mySmartUpload = new SmartUpload();
			mySmartUpload.setCharset("UTF-8");
			nseer_db_backup1 qcs_db = new nseer_db_backup1(dbApplication);
			nseer_db_backup1 qcs_db1 = new nseer_db_backup1(dbApplication);
			if (qcs_db.conn((String)dbSession.getAttribute("unit_db_name")) && qcs_db1.conn((String)dbSession.getAttribute("unit_db_name")))
				try
				{
					String purchase_id = request.getParameter("purchase_id");
					String sqla = (new StringBuilder("update purchase_purchase set qcs_apply_tag='1',gather_tag='3' where purchase_id='")).append(purchase_id).append("'").toString();
					qcs_db1.executeUpdate(sqla);
					sqla = (new StringBuilder("select provider_id,provider_name from purchase_details where purchase_id='")).append(purchase_id).append("' and qcs_apply_tag='0'").toString();
					String sql;
					for (ResultSet rs = qcs_db1.executeQuery(sqla); rs.next(); qcs_db.executeUpdate(sql))
					{
						sql = (new StringBuilder("update stock_gather set qcs_dealwith_tag='1' where reasonexact='")).append(purchase_id).append("' and reasonexact_details='").append(rs.getString("provider_name")).append("'").toString();
						qcs_db.executeUpdate(sql);
						sql = (new StringBuilder("update fund_fund set qcs_dealwith_tag='1' where reasonexact='")).append(purchase_id).append("' and funder_id='").append(rs.getString("provider_id")).append("'").toString();
					}

					qcs_db1.commit();
					qcs_db.commit();
					qcs_db1.close();
					qcs_db.close();
				}
				catch (Exception ex)
				{
					response.sendRedirect("qcs/qcs/purchase_register_ok.jsp?finished_tag=1");
				}
			else
				response.sendRedirect("error_conn.htm");
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
